package org.luu.medicare.controller.medicareInfoController;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.luu.medicare.common.Result;
import org.luu.medicare.entity.PageBean;
import org.luu.medicare.entity.TMedicalInstitution;
import org.luu.medicare.service.MedicalInstitutionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/institution")
@Slf4j
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class MedicalInstitutionController {
    private final MedicalInstitutionService medicalInstitutionService;

    @GetMapping
    public Result<PageBean<TMedicalInstitution>> page(@RequestParam(defaultValue = "1") int page,
                                                      @RequestParam(defaultValue = "10") int pageSize,
                                                      String name,
                                                      String id) {
        log.info("定点医疗机构 page: {}, pageSize: {}, name: {}, id: {}", page, pageSize, name, id);
        return medicalInstitutionService.page(page, pageSize, name, id);
    }

    @GetMapping("/{id}")
    public Result<TMedicalInstitution> findById(@PathVariable Integer id) {
        log.info("定点医疗机构 findById: {}", id);
        return medicalInstitutionService.findById(id);
    }

    @DeleteMapping("/{id}")
    public Result<String> deleteById(@PathVariable Integer id) {
        log.info("定点医疗机构 deleteById: {}", id);
        return medicalInstitutionService.deleteById(id);
    }

    @PostMapping
    public Result<String> save(@RequestBody TMedicalInstitution medicalInstitution) {
        log.info("定点医疗机构 save: {}", medicalInstitution);
        return medicalInstitutionService.save(medicalInstitution);
    }

    @PutMapping
    public Result<String> update(@RequestBody TMedicalInstitution medicalInstitution) {
        log.info("定点医疗机构 update: {}", medicalInstitution);
        return medicalInstitutionService.update(medicalInstitution);
    }
}
